package lazy2.tool.beangenerator;

import java.sql.Connection;
import java.sql.ResultSetMetaData;
import java.sql.SQLException;

import lazy2.util.StringUtil;

class DatabaseConnection {
	DBType dbType;
	Connection connection;
	
	boolean isOpen() throws SQLException {
		return connection!=null && !connection.isClosed();
	}
	boolean isClosed() throws SQLException {
		return !isOpen();
	}
	
	PrimaryKeyInfo isPrimaryKey(String tableName, String columnName) throws SQLException {
		if(dbType!=null
		&& connection!=null
		&& StringUtil.hasText(tableName)
		&& StringUtil.hasText(columnName)) {
			return dbType.isPrimaryKey(connection, tableName, columnName);
		}
		return null;
	}
	ResultSetMetaData getTableMetaData(String tableName) throws SQLException {
		if(dbType!=null
		&& connection!=null
		&& StringUtil.hasText(tableName)) {
			return dbType.getTableMetaData(connection, tableName);
		}
		return null;
	}
}
